<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-6-26
 * Time: 11:12
 */
namespace wxpay;

use think\Session;

class H5Pay
{
    //$data 金额和订单号
    public function wxh5Request($data)
    {

        $appid = 'wxf4b7b2771a83d60b';
        $mch_id = '1530809431';//商户号
        $key = '63bdd8ce57da5f738f561b02945609ae';//商户key
        $notify_url = "http://wei.774945135.top";//回调地址
        $params['body'] = $data['describe'];                       //商品描述
        $params['out_trade_no'] = $data['orderNum'];    //自定义的订单号
        $params['total_fee'] = $data['totalPrice'] * 100;                       //订单金额 只能为整数 单位为分
        $params['openid'] = Session::get('openid');//$data['openid'];
        $params['trade_type'] = 'JSAPI';                   //交易类型 JSAPI | NATIVE | APP | WAP
        $wxPay = new WxPay($appid,$mch_id,$notify_url,$key);
        $result = $wxPay->unifiedOrder($params);
        if ($result['result_code'] == 'SUCCESS' && $result['return_code'] == 'SUCCESS') {
            $res = $wxPay->h5Sign($result);
            return json($res);
        }
    }
}